<script setup lang="ts">
import {onMounted, ref} from "vue";
import router from "@/router/index.js";
import {useRoute} from "vue-router";
import {getOneLocationAPI} from "@/apis/location.js";
import {getUserDetailByIdAPI} from "@/apis/userManage.js";
import {getOneProjectAPI} from "@/apis/projectInfo.js";
import {useGetWarehouseByIdAPI} from "@/apis/warehouse.js";

const route=useRoute();
interface location {
  userId:number,
  projectId:number,
  warehouseId:number,
  locationAddress:string,
  description:string,
}
const locationInfo=ref<location>();

interface user {
  id:number,
  loginName:string,
  realName:string,
}
const userInfo=ref<user>();

interface project{
  id:number,
  name:string,
}
const projectInfo=ref<project>();

interface warehouse{
  id:number,
  name:string,
}
const warehouseInfo=ref<warehouse>();




onMounted(async () => {
  if(route.params.id===null||route.params.id===undefined){
    await router.push("/manage/locationManager");
  }else {
    await getOneLocationAPI(Number(route.params.id)).then(res=>{
      locationInfo.value=res.data;
      console.log(locationInfo.value);
    })

   await getUserDetailByIdAPI(locationInfo.value.userId).then(res=>{
      userInfo.value=res.data;
      console.log(userInfo.value?.loginName);
    })

    await getOneProjectAPI(locationInfo.value.projectId).then(res=>{
      projectInfo.value=res.data;
      console.log(projectInfo.value.name);
    })

    await useGetWarehouseByIdAPI(locationInfo.value?.warehouseId).then(res=>{
      warehouseInfo.value=res.data;
      console.log(warehouseInfo.value.name);
    })


  }
})

</script>

<template>
LocationDetail
</template>

<style scoped lang="scss">

</style>